{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Maximum Ascending Subarray Sum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: maxAscendingSum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #最大升序子数组和"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个正整数组成的数组 <code>nums</code> ，返回 <code>nums</code> 中一个 <strong>升序 </strong>子数组的最大可能元素和。</p>\n",
    "\n",
    "<p>子数组是数组中的一个连续数字序列。</p>\n",
    "\n",
    "<p>已知子数组 <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> ，若对所有 <code>i</code>（<code>l <= i < r</code>），<code>nums<sub>i </sub> < nums<sub>i+1</sub></code> 都成立，则称这一子数组为 <strong>升序</strong> 子数组。注意，大小为 <code>1</code> 的子数组也视作 <strong>升序</strong> 子数组。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [10,20,30,5,10,50]\n",
    "<strong>输出：</strong>65\n",
    "<strong>解释：</strong>[5,10,50] 是元素和最大的升序子数组，最大元素和为 65 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [10,20,30,40,50]\n",
    "<strong>输出：</strong>150\n",
    "<strong>解释：</strong>[10,20,30,40,50] 是元素和最大的升序子数组，最大元素和为 150 。 \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [12,17,15,13,10,11,12]\n",
    "<strong>输出：</strong>33\n",
    "<strong>解释：</strong>[10,11,12] 是元素和最大的升序子数组，最大元素和为 33 。 \n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>nums = [100,10,1]\n",
    "<strong>输出：</strong>100\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= nums.length <= 100</code></li>\n",
    "\t<li><code>1 <= nums[i] <= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [maximum-ascending-subarray-sum](https://leetcode.cn/problems/maximum-ascending-subarray-sum/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [maximum-ascending-subarray-sum](https://leetcode.cn/problems/maximum-ascending-subarray-sum/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[10,20,30,5,10,50]', '[10,20,30,40,50]', '[12,17,15,13,10,11,12]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        total=pre=max_total=nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>pre:\n",
    "                total+=nums[i]\n",
    "            else:\n",
    "                total=nums[i]\n",
    "            pre=nums[i]\n",
    "            max_total=max(max_total,total)\n",
    "        return max_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        curmax = nums[0]\n",
    "        nummax = nums[0]\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] <= nums[i-1]:\n",
    "                curmax = nums[i]\n",
    "                nummax = max(nummax, curmax)\n",
    "            else:\n",
    "                curmax += nums[i]\n",
    "                nummax = max(nummax, curmax)\n",
    "        return nummax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res=[]\n",
    "        count=1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                count+=1\n",
    "            else:\n",
    "                res.append(sum(nums[i-count:i]))                \n",
    "                count=1\n",
    "        res.append(sum(nums[len(nums)-count:]))\n",
    "        \n",
    "        res.sort()    \n",
    "        #print(res)    \n",
    "        return res[-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        maxsum = nums[0]\n",
    "        pos = 0\n",
    "        size = len(nums)\n",
    "        nums.append(-1)\n",
    "        for i in range(1, size + 1):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                continue\n",
    "            currsum = sum(nums[pos: i])\n",
    "            pos = i\n",
    "            if currsum > maxsum:\n",
    "                maxsum = currsum\n",
    "        return maxsum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        t=0\n",
    "        for i,v in enumerate(nums):\n",
    "            if i==0 or v>nums[i-1]:\n",
    "                t+=v\n",
    "                ans=max(t,ans)\n",
    "            else:\n",
    "                t=v\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        stack = []\n",
    "        n = len(nums)\n",
    "\n",
    "        sum_lst = []\n",
    "\n",
    "        for i in range(n):\n",
    "            if stack and stack[-1] >= nums[i]:\n",
    "                sum_lst.append(sum(stack))\n",
    "                stack = []\n",
    "            stack.append(nums[i])\n",
    "            #print('stack=', stack)\n",
    "            #print('sum_lst', sum_lst)\n",
    "        \n",
    "        if stack:\n",
    "            sum_lst.append(sum(stack))\n",
    "        \n",
    "        print(sum_lst)\n",
    "        return max(sum_lst)\n",
    "                \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res=[]\n",
    "        count=1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                count+=1\n",
    "            else:\n",
    "                res.append(sum(nums[i-count:i]))                \n",
    "                count=1\n",
    "        res.append(sum(nums[len(nums)-count:]))\n",
    "        \n",
    "        res.sort()    \n",
    "        print(res)    \n",
    "        return res[-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        n=len(nums)\n",
    "        dp=[0]*n\n",
    "        dp[0]=nums[0]\n",
    "        for i in range(1,n):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i]=dp[i-1]+nums[i]\n",
    "            else:\n",
    "                dp[i]=nums[i]\n",
    "        return max(dp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, n = 0, len(nums)\n",
    "        while i < n:\n",
    "            s = nums[i]\n",
    "            i += 1\n",
    "            while i < n and nums[i] > nums[i - 1]:\n",
    "                s += nums[i]\n",
    "                i += 1\n",
    "            ans = max(ans, s)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        stack = []\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            if len(stack) == 0:\n",
    "                stack.append(num)\n",
    "            else:\n",
    "                if num > stack[-1]:\n",
    "                    stack.append(num)\n",
    "                elif num <= stack[-1]:\n",
    "                    res = max(res, sum(stack))\n",
    "                    stack = []\n",
    "                    stack.append(num)\n",
    "        res = max(res, sum(stack))\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = nums[0]\n",
    "        nums.append(0)\n",
    "        pre = 0\n",
    "        sum_ = 0\n",
    "        for num in nums:\n",
    "            if num > pre:\n",
    "                sum_ += num\n",
    "                pre = num\n",
    "            else:\n",
    "                res = max(res,sum_)\n",
    "                sum_ = num\n",
    "                pre = num\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        result = 0\n",
    "        temp = nums[0]\n",
    "        last = nums[0]\n",
    "        for i in nums:\n",
    "            if i > last:\n",
    "                temp = temp + i\n",
    "            else:\n",
    "                result = max(result, temp)\n",
    "                temp = i\n",
    "            last = i\n",
    "        result = max(result, temp)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        a=nums[0]\n",
    "        max=nums[0]\n",
    "        i,j=0,1\n",
    "        while j<len(nums):\n",
    "            if nums[i]<nums[j]:\n",
    "                a+=nums[j]\n",
    "                if max<a:\n",
    "                    max=a\n",
    "            else:\n",
    "                a=nums[j]\n",
    "            i+=1\n",
    "            j+=1\n",
    "        return max\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ad={}\n",
    "        count=1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                count+=1\n",
    "            else:\n",
    "                ssum=sum(nums[i-count:i])\n",
    "                if ssum not in ad:\n",
    "                    ad[ssum]=[nums[i-count:i]]\n",
    "                else:\n",
    "                    ad[ssum].append(nums[i-count:i])\n",
    "                count=1\n",
    "        tsum=sum(nums[len(nums)-count:])\n",
    "        if tsum not in ad:\n",
    "            ad[tsum]=[nums[len(nums)-count:]]\n",
    "        else:\n",
    "            ad[tsum].append(nums[len(nums)-count:])\n",
    "        #print(ad)\n",
    "        mxad=[k for k in ad]\n",
    "        mxad.sort()        \n",
    "        return mxad[-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = temp = nums[0]\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                temp += nums[i]\n",
    "            else:\n",
    "                res = max(res, temp)\n",
    "                temp = nums[i]\n",
    "        res = max(res, temp)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        x = k = s = 0\n",
    "        nums.append(0)\n",
    "        for i in nums:\n",
    "            if i <= x:\n",
    "                s = max(s,k)\n",
    "                k = i\n",
    "            else:\n",
    "                k += i\n",
    "            x = i\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        max_total=total=0\n",
    "        i=0\n",
    "        while i<len(nums):\n",
    "            total+=nums[i]\n",
    "            if i>0 and nums[i]>nums[i-1]:\n",
    "                max_total=max(max_total,total)\n",
    "                i+=1\n",
    "            else:\n",
    "                total=nums[i]\n",
    "                max_total=max(max_total,total)\n",
    "                i+=1\n",
    "        return max_total\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        maxSum = nums[0]\n",
    "        currSum = nums[0]\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] <= nums[i-1]:\n",
    "                maxSum = max(maxSum, currSum)\n",
    "                currSum = nums[i]\n",
    "            else:\n",
    "                currSum += nums[i]\n",
    "                maxSum = max(maxSum, currSum)\n",
    "        return maxSum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "      res = 0\n",
    "      cur = [nums[0]]\n",
    "      for i in nums[1:]:\n",
    "          if cur[-1] < i:\n",
    "              cur.append(i)\n",
    "          else:\n",
    "              res = max(res, sum(cur))\n",
    "              cur = [i]\n",
    "      return max(res, sum(cur))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: list[int]) -> int:\n",
    "        numGroup = []\n",
    "        idx, left = 0, 0\n",
    "        while idx < len(nums):\n",
    "            if idx == len(nums) - 1:\n",
    "                numGroup.append(nums[left:])\n",
    "                break\n",
    "            if nums[idx] >= nums[idx+1]:\n",
    "                numGroup.append(nums[left:idx+1])\n",
    "                left = idx + 1\n",
    "            idx += 1\n",
    "        return max((sum(x) for x in numGroup))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        s=nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i-1]<nums[i]:\n",
    "                s+=nums[i]\n",
    "            else:\n",
    "                ans=max(s,ans)\n",
    "                s=nums[i]\n",
    "        ans=max(s,ans)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "      res = 0\n",
    "      cur = [nums[0]]\n",
    "      for i in nums[1:]:\n",
    "          if cur[-1] < i:\n",
    "              cur.append(i)\n",
    "          else:\n",
    "              res = max(res, sum(cur))\n",
    "              cur = [i]\n",
    "      return max(res, sum(cur))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "      res = 0\n",
    "      cur = [nums[0]]\n",
    "      for i in nums[1:]:\n",
    "          if cur[-1] < i:\n",
    "              cur.append(i)\n",
    "          else:\n",
    "              res = max(res, sum(cur))\n",
    "              cur = [i]\n",
    "      return max(res, sum(cur))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans, j, s = 0, 1, nums[0]\n",
    "        while j < len(nums):\n",
    "            if nums[j] > nums[j - 1]:\n",
    "                s += nums[j]\n",
    "            else:\n",
    "                ans = max(ans, s)\n",
    "                s = nums[j]\n",
    "            j += 1\n",
    "        return max(ans, s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans=j=0\n",
    "        for i in range(len(nums)):\n",
    "            if i==0 or nums[i]>nums[i-1]:\n",
    "                j+=nums[i]\n",
    "                ans=max(ans,j)\n",
    "            else:\n",
    "                j=nums[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        # ans = 0\n",
    "        # i, n = 0, len(nums)\n",
    "        # while i < n:\n",
    "        #     s = nums[i]\n",
    "        #     i += 1\n",
    "        #     while i < n and nums[i] > nums[i - 1]:\n",
    "        #         s += nums[i]\n",
    "        #         i += 1\n",
    "        #     ans = max(ans, s)\n",
    "        # return ans\n",
    "\n",
    "        # dp = [0] * len(nums)\n",
    "        # dp[0] = nums[0]\n",
    "        # for i in range(1, len(nums)):\n",
    "        #     if nums[i-1] < nums[i]:\n",
    "        #         dp[i] = dp[i-1] + nums[i]\n",
    "        #     else:\n",
    "        #         dp[i] = nums[i]\n",
    "        # return max(dp) \n",
    "\n",
    "        ans = t = 0\n",
    "        for i, v in enumerate(nums):\n",
    "            if i == 0 or v > nums[i - 1]:\n",
    "                t += v\n",
    "                ans = max(ans, t)\n",
    "            else:\n",
    "                t = v\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "    \n",
    "    \n",
    "        ans = t = 0\n",
    "        for i, v in enumerate(nums):\n",
    "            if i == 0 or v > nums[i - 1]:\n",
    "                t += v\n",
    "                ans = max(ans, t)\n",
    "            else:\n",
    "                t = v\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        max=0\n",
    "        value=0\n",
    "        for i in range(len(nums)):\n",
    "            \n",
    "            value=value+nums[i]\n",
    "            if value>max:\n",
    "                max=value\n",
    "            if i!=len(nums)-1 and nums[i+1]<=nums[i]:\n",
    "                value=0\n",
    "        return max\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        #滑动窗口\n",
    "        ln=len(nums)\n",
    "        if ln==1:\n",
    "            return nums[0]\n",
    "        right = 1\n",
    "        curr_sm = nums[0]\n",
    "        max_sm = 0\n",
    "        while right<ln:\n",
    "            if nums[right]>nums[right-1]:\n",
    "                curr_sm+=nums[right]\n",
    "            else:\n",
    "                max_sm=max(max_sm,curr_sm)\n",
    "                curr_sm=nums[right]\n",
    "            right+=1\n",
    "        max_sm = max(max_sm, curr_sm)\n",
    "        return max_sm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        i, j = 0, 1\n",
    "        ans = cur = nums[i]\n",
    "        while i < len(nums) and j < len(nums):\n",
    "            if nums[j] > nums[j - 1]:\n",
    "                cur += nums[j]\n",
    "                j += 1\n",
    "            else:\n",
    "                i += 1\n",
    "                j = i + 1\n",
    "                if i < len(nums):\n",
    "                    cur = nums[i]\n",
    "            ans = max(ans, cur)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        total=pre=max_total=nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>pre:\n",
    "                total+=nums[i]\n",
    "            else:\n",
    "                total=nums[i]\n",
    "            pre=nums[i]\n",
    "            max_total=max(max_total,total)\n",
    "        return max_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, n = 0, len(nums)\n",
    "\n",
    "        while i<n:\n",
    "            s = nums[i]\n",
    "            i += 1\n",
    "            while i<n and nums[i]>nums[i-1]:\n",
    "                s += nums[i]\n",
    "                i += 1\n",
    "            ans = max(ans,s)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, n = 0, len(nums)\n",
    "        while i < n:\n",
    "            s = nums[i]\n",
    "            i += 1\n",
    "            while i < n and nums[i] > nums[i - 1]:\n",
    "                s += nums[i]\n",
    "                i += 1\n",
    "            ans = max(ans, s)\n",
    "        return ans\n",
    "\n",
    "        # dp = [0] * len(nums)\n",
    "        # dp[0] = nums[0]\n",
    "        # for i in range(1, len(nums)):\n",
    "        #     if nums[i-1] < nums[i]:\n",
    "        #         dp[i] = dp[i-1] + nums[i]\n",
    "        #     else:\n",
    "        #         dp[i] = nums[i]\n",
    "        # return max(dp) \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        start, n = 0, len(nums)\n",
    "\n",
    "        while start < n:\n",
    "            tmp = 0\n",
    "            \n",
    "            while start + 1 < n and nums[start + 1] > nums[start]:\n",
    "                tmp += nums[start]\n",
    "                start += 1\n",
    "            tmp += nums[start]\n",
    "            start += 1\n",
    "            res = max(tmp, res)\n",
    "        return res\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "\n",
    "        ans = 0\n",
    "        i, n = 0, len(nums)\n",
    "        while i < n:\n",
    "            s = nums[i]\n",
    "            i += 1\n",
    "            while i < n and nums[i] > nums[i - 1]:\n",
    "                s += nums[i]\n",
    "                i += 1\n",
    "            ans = max(ans, s)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans, cur = nums[0], nums[0]\n",
    "        for last, num in pairwise(nums):\n",
    "            cur = cur + num if last < num else num\n",
    "            ans = max(ans, cur)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        nums.append(0)\n",
    "        st, res, tmp = 0, 0, nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                tmp += nums[i]\n",
    "                continue\n",
    "            else:\n",
    "                res = max(res,tmp)\n",
    "                st, tmp = i, nums[i]\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        dp=[0]*len(nums)\n",
    "        dp[0] = nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                    dp[i]=dp[i-1] + nums[i]\n",
    "            else:\n",
    "                dp[i] = nums[i]\n",
    "        return max(dp)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        start, n = 0, len(nums)\n",
    "\n",
    "        while start < n:\n",
    "            tmp = 0\n",
    "            while start + 1 < n and nums[start + 1] > nums[start]:\n",
    "                tmp += nums[start]\n",
    "                start += 1\n",
    "            tmp += nums[start]\n",
    "            start += 1\n",
    "            res = max(tmp, res)\n",
    "        return res\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        v=nums[0]\n",
    "        res=[nums[0]]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                v+=nums[i]\n",
    "                res.append(v)\n",
    "            else:\n",
    "                v=nums[i]\n",
    "                res.append(v)\n",
    "        print(res)\n",
    "        return max(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        a = []\n",
    "        result = 0\n",
    "        for i in nums:\n",
    "            if not a or i>a[-1]:\n",
    "                a.append(i)\n",
    "            else: \n",
    "                result = max(result, sum(a))\n",
    "                a = []\n",
    "                a.append(i)\n",
    "        result = max(result, sum(a))\n",
    "        return result\n",
    "            \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        length = len(nums)\n",
    "        if len(nums) == 0:\n",
    "            return 0\n",
    "\n",
    "        output = res = nums[0]\n",
    "        for index in range(1, length):\n",
    "            if nums[index] <= nums[index - 1]:\n",
    "                res = nums[index]\n",
    "            else:\n",
    "                res += nums[index]\n",
    "            output = max(res, output)\n",
    "        return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        max_sum = 0\n",
    "        asc_lst = []\n",
    "        \n",
    "        for n in nums:\n",
    "            if not asc_lst:\n",
    "                asc_lst.append(n)\n",
    "            else:\n",
    "                if asc_lst[-1] < n:\n",
    "                    asc_lst.append(n)\n",
    "                else:\n",
    "                    max_sum = max(max_sum, sum(asc_lst))\n",
    "                    asc_lst.clear()\n",
    "                    asc_lst.append(n)\n",
    "            \n",
    "        max_sum = max(max_sum, sum(asc_lst))\n",
    "        return max_sum "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "      if len(nums)==1:\n",
    "        return sum(nums)\n",
    "      ans=0\n",
    "      i=0\n",
    "      while i<len(nums):\n",
    "        s=nums[i]\n",
    "        i+=1\n",
    "        while i<len(nums) and nums[i]>nums[i-1]:\n",
    "          s+=nums[i]\n",
    "          i+=1\n",
    "        ans=max(s,ans)\n",
    "      return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        tmp = max_res = nums[0]\n",
    "        for i in range(len(nums)-1):\n",
    "            if nums[i+1] > nums[i]:\n",
    "                tmp += nums[i+1]\n",
    "            else:\n",
    "                tmp = nums[i+1]\n",
    "            if tmp > max_res:\n",
    "                max_res = tmp\n",
    "        return max_res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        maxsum = 0\n",
    "        size = len(nums)\n",
    "        pos = 0\n",
    "        while pos < size:\n",
    "            currsum = nums[pos]\n",
    "            pos += 1\n",
    "            while pos < size and nums[pos] > nums[pos - 1]:\n",
    "                currsum += nums[pos]\n",
    "                pos += 1\n",
    "            if currsum > maxsum:\n",
    "                maxsum = currsum\n",
    "        return maxsum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans=0\n",
    "        i,n = 0,len(nums)\n",
    "        while i<n:\n",
    "            s=nums[i]\n",
    "            i+=1\n",
    "            while i<n and nums[i]>nums[i-1]:\n",
    "                s+=nums[i]\n",
    "                i+=1\n",
    "            ans = max(ans,s)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        start, n = 0, len(nums)\n",
    "\n",
    "        while start < n:\n",
    "            tmp = 0\n",
    "            while start + 1 < n and nums[start + 1] > nums[start]:\n",
    "                tmp += nums[start]\n",
    "                start += 1\n",
    "            tmp += nums[start]\n",
    "            start += 1\n",
    "            res = max(tmp, res)\n",
    "        return res\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        #滑动窗口\n",
    "        ln=len(nums)\n",
    "        if ln==1:\n",
    "            return nums[0]\n",
    "        right = 1\n",
    "        curr_sm = nums[0]\n",
    "        max_sm = 0\n",
    "        while right<ln:\n",
    "            if nums[right]>nums[right-1]:\n",
    "                curr_sm+=nums[right]\n",
    "            else:\n",
    "                max_sm=max(max_sm,curr_sm)\n",
    "                curr_sm=nums[right]\n",
    "            right+=1\n",
    "        # max_sm = max(max_sm, curr_sm)\n",
    "        return max(max_sm, curr_sm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        bigger_sum = nums[0]\n",
    "        result = []\n",
    "        i = 0\n",
    "        a = 0\n",
    "        while i < len(nums)-1 :\n",
    "            if nums[i] < nums[i+1]:\n",
    "                bigger_sum += nums[i+1]\n",
    "            else:\n",
    "                result.append(bigger_sum)\n",
    "                bigger_sum = nums[i+1]\n",
    "            i += 1\n",
    "        result.append(bigger_sum)\n",
    "        return max(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ref = 0\n",
    "        nlen = len(nums)\n",
    "        a = nums[0]\n",
    "        for i in range(1,nlen):\n",
    "            if nums[i] > nums[i-1]:\n",
    "                a += nums[i]\n",
    "            else:\n",
    "                ref = max(ref,a)\n",
    "                a = nums[i]\n",
    "        ref = max(ref,a)\n",
    "        return ref\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        mx = sm = nums[0]\n",
    "        ln = len(nums)\n",
    "        i = 1\n",
    "        while i < ln:\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                sm += nums[i]\n",
    "            else:\n",
    "                sm = nums[i]\n",
    "            mx = max(mx, sm)\n",
    "            i += 1\n",
    "        return mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        max_sum = nums[0]\n",
    "        cur_sum = nums[0]\n",
    "\n",
    "        for i in range(1, len(nums)):\n",
    "            cur_sum = cur_sum + nums[i] if nums[i] > nums[i - 1] else nums[i]\n",
    "            max_sum = max(max_sum, cur_sum)\n",
    "\n",
    "        return max_sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        i, j = 0, 1\n",
    "        sum_num = 0\n",
    "        l = []\n",
    "        while j < len(nums):\n",
    "            if nums[i] < nums[j] and nums[j - 1] < nums[j]:\n",
    "                j += 1\n",
    "            else:\n",
    "                l.append(sum(nums[i:j]))\n",
    "                i = j\n",
    "                j += 1\n",
    "            l.append(sum(nums[i:j]))\n",
    "        l.append(nums[0])\n",
    "        return max(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        s = ans = 0\n",
    "        for i, x in enumerate(nums):\n",
    "            if i and nums[i - 1] >= nums[i]:\n",
    "                s = 0\n",
    "            s += x\n",
    "            ans = max(ans, s)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        sumSubMax = 0\n",
    "        n = len(nums)\n",
    "        i = 0\n",
    "        while i<n:\n",
    "            subArr = [nums[i]]\n",
    "            k = 0\n",
    "            while i+k+1<n and nums[i+k] < nums[i+k+1]:\n",
    "                subArr.append(nums[i+k+1])\n",
    "                k = k + 1\n",
    "            sumSubMax = max(sumSubMax,sum(subArr))\n",
    "            i = i + k + 1\n",
    "        return sumSubMax"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        last = 0\n",
    "        res = 0\n",
    "        tmp = 0\n",
    "        for num in nums:\n",
    "            if last < num:\n",
    "                tmp += num\n",
    "                res = max(res, tmp)\n",
    "            else:\n",
    "                tmp = num\n",
    "            last = num\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = nums[0]\n",
    "        n = len(nums)\n",
    "        cur=0\n",
    "        for i in range(n):\n",
    "            if nums[i-1]<nums[i]:\n",
    "                cur+=nums[i]\n",
    "            else:\n",
    "                cur=nums[i]\n",
    "            res=max(res,cur)\n",
    "        print(res)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        maxsum = nums[0]\n",
    "        pos = 0\n",
    "        size = len(nums)\n",
    "        for i in range(1, size):\n",
    "            currsum = 0\n",
    "            if nums[i] <= nums[i - 1]:\n",
    "                currsum = sum(nums[pos: i])\n",
    "                pos = i\n",
    "            elif i == size - 1:\n",
    "                currsum = sum(nums[pos: size])\n",
    "            if currsum > maxsum:\n",
    "                maxsum = currsum\n",
    "        return maxsum\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        #动态规划\n",
    "        #dp[i]表示以i位置结尾的最升序和\n",
    "        n = len(nums)\n",
    "        dp = [0]*n\n",
    "        dp[0] = nums[0]\n",
    "        res = dp[0]\n",
    "        for i in range(1,n):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                dp[i] = dp[i-1]+nums[i]\n",
    "            else:\n",
    "                dp[i] = nums[i]\n",
    "            res = max(dp[i],res)\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res=[]\n",
    "        count=1\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>nums[i-1]:\n",
    "                count+=1\n",
    "            else:\n",
    "                res.append(sum(nums[i-count:i]))                \n",
    "                count=1\n",
    "        res.append(sum(nums[len(nums)-count:]))\n",
    "        \n",
    "        res.sort()    \n",
    "        #print(res)    \n",
    "        return res[-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        x = nums[0]\n",
    "        y = 0\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] <= nums[i-1]:\n",
    "                y = max(x, y)\n",
    "                x = 0\n",
    "            x += nums[i]\n",
    "        return max(x, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        #滑动窗口\n",
    "        ln=len(nums)\n",
    "        if ln==1:\n",
    "            return nums[0]\n",
    "        right = 1\n",
    "        curr_sm = nums[0]\n",
    "        max_sm = 0\n",
    "        while right<ln:\n",
    "            if nums[right]>nums[right-1]:\n",
    "                curr_sm+=nums[right]\n",
    "            else:\n",
    "                max_sm=max(max_sm,curr_sm)\n",
    "                curr_sm=nums[right]\n",
    "            right+=1\n",
    "        max_sm = max(max_sm, curr_sm)\n",
    "        return max_sm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        start, n = 0, len(nums)\n",
    "\n",
    "        while start < n:\n",
    "            tmp = 0\n",
    "            while start + 1 < n and nums[start + 1] > nums[start]:\n",
    "                tmp += nums[start]\n",
    "                start += 1\n",
    "            tmp += nums[start]\n",
    "            start += 1\n",
    "            res = max(tmp, res)\n",
    "        return res\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        total=pre=max_total=nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            if nums[i]>pre:\n",
    "                total+=nums[i]\n",
    "            else:\n",
    "                total=nums[i]\n",
    "            pre=nums[i]\n",
    "            max_total=max(max_total,total)\n",
    "        return max_total"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        flag = nums[0]\n",
    "        m = 0\n",
    "        i = 1\n",
    "        while i < len(nums):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                flag += nums[i]\n",
    "                i += 1\n",
    "            else:\n",
    "                m = max(m, flag)\n",
    "                flag = nums[i]\n",
    "                i += 1\n",
    "        \n",
    "        return max(m, flag)\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        ans = 0\n",
    "        i, n = 0, len(nums)\n",
    "        while i < n:\n",
    "            s = nums[i]\n",
    "            i += 1\n",
    "            while i < n and nums[i] > nums[i - 1]:\n",
    "                s += nums[i]\n",
    "                i += 1\n",
    "            ans = max(ans, s)\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0]\n",
    "        flag = nums[0]\n",
    "        m = 0\n",
    "        i = 1\n",
    "        while i < len(nums):\n",
    "            if nums[i] > nums[i - 1]:\n",
    "                flag += nums[i]\n",
    "                i += 1\n",
    "            else:\n",
    "                m = max(m, flag)\n",
    "                flag = nums[i]\n",
    "                i += 1\n",
    "    \n",
    "        return max(m, flag)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res=0\n",
    "        stack=[]\n",
    "        i=0\n",
    "        l=len(nums)\n",
    "        while i<l:\n",
    "            if not stack:\n",
    "                stack.append(nums[i])\n",
    "                i+=1\n",
    "            elif nums[i]>stack[-1]:\n",
    "                stack.append(nums[i])\n",
    "                i+=1\n",
    "            else:\n",
    "                res=max(res,sum(stack))\n",
    "                stack=[nums[i]]\n",
    "                i+=1\n",
    "        res=max(res,sum(stack))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        start, n = 0, len(nums)\n",
    "\n",
    "        while start < n:\n",
    "            tmp = 0\n",
    "            \n",
    "            while start + 1 < n and nums[start + 1] > nums[start]:\n",
    "                tmp += nums[start]\n",
    "                start += 1\n",
    "            tmp += nums[start]\n",
    "            start += 1\n",
    "            res = max(tmp, res)\n",
    "        return res\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        start, n = 0, len(nums)\n",
    "\n",
    "        while start < n:\n",
    "            tmp = 0\n",
    "            while start + 1 < n and nums[start + 1] > nums[start]:\n",
    "                tmp += nums[start]\n",
    "                start += 1\n",
    "            tmp += nums[start]\n",
    "            start += 1\n",
    "            res = max(tmp, res)\n",
    "        return res\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        res = 0\n",
    "        start, n = 0, len(nums)\n",
    "\n",
    "        while start < n:\n",
    "            tmp = 0\n",
    "            \n",
    "            while start + 1 < n and nums[start + 1] > nums[start]:\n",
    "                tmp += nums[start]\n",
    "                start += 1\n",
    "            tmp += nums[start]\n",
    "            start += 1\n",
    "            res = max(tmp, res)\n",
    "        return res\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def maxAscendingSum(self, nums: List[int]) -> int:\n",
    "        n = len(nums)\n",
    "        cur_sum = nums[0]\n",
    "        res = nums[0]\n",
    "        for i in range(1, n):\n",
    "            if nums[i-1] < nums[i]:\n",
    "                cur_sum += nums[i]\n",
    "            else:\n",
    "                cur_sum = nums[i]\n",
    "            res = max(res, cur_sum)\n",
    "        return res\n",
    "            \n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
